package stdying.handyweibo.ui.auth;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.OnClick;
import stdying.handyweibo.MainActivity;
import stdying.handyweibo.R;
import stdying.handyweibo.injection.component.DaggerWeiboAuthComponent;
import stdying.handyweibo.injection.component.WeiboAuthComponent;
import stdying.handyweibo.injection.module.WBAuthActivityModule;
import stdying.handyweibo.presenter.WeiboAuthPresenter;
import stdying.handyweibo.ui.BaseActivity;
import stdying.handyweibo.view.IAuthView;


/**
 * 授权登录
 */
public class WBAuthActivity extends BaseActivity implements IAuthView{

    private WeiboAuthComponent mWeiboAuthComponent;

    @Inject
    WeiboAuthPresenter mWeiboAuthPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wbauth);

        ButterKnife.bind(this);
        //mWeiboAuthPresenter = new WeiboAuthPresenter(this);
        //initInjector();
    }


    /**
     * 初始化注入
     */
    protected void initInjector(){
       this.mWeiboAuthComponent = DaggerWeiboAuthComponent.builder()
               .wBAuthActivityModule(new WBAuthActivityModule(this))
               .build();
        this.mWeiboAuthComponent.inject(this);

    }

    public WeiboAuthComponent getWeiboAuthComponent(){
        return this.mWeiboAuthComponent;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mWeiboAuthPresenter.ssoCallBack(requestCode, resultCode, data);
    }

    @OnClick(R.id.but_auth_weibo)
    void weiboAuthLogin(){
        mWeiboAuthPresenter.weiboAuthLogin();
    }

    @Override
    public void authLoginSuccess() {
        Toast.makeText(this,R.string.auth_weibo_success,Toast.LENGTH_SHORT).show();
        //跳转主页面
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void authLoginCancle() {
        Toast.makeText(this,R.string.auth_weibo_cancel,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void authLoginFailure() {
        Toast.makeText(this,R.string.auth_weibo_failed,Toast.LENGTH_SHORT).show();
    }
}
